package string.test;

import string.inter.CustString;
import string.sequentialstring.SeqString;

public class StringMain {
    public static char[] arr = new char[]{'a', 'b', 'a', 'c', 'e', 'a', 'b'};
    public static CustString str = new SeqString(arr);

    public static void main(String[] args) {
        str.printStr();
        test();
//        nextTest();
//        kmpTest();
    }

    public static void test() {
        System.out.println("在位置1处（从0开始）插入字符串yzn:");
        str.strInsert(new SeqString(new char[]{'y', 'z', 'n'}), 1);
        str.printStr();
        System.out.println("串长度：" + str.strLength());
        System.out.println("从位置3处（从0开始）开始删除4个字符：");
        str.strDelete(3, 4);
        str.printStr();
        System.out.println("串长度：" + str.strLength());
        System.out.println("从2位置开始匹配字符串ab:");
        System.out.println(str.index(new SeqString(new char[]{'a', 'b'}), 2));
        System.out.println("从0位置匹配xyz字符串：");
        System.out.println(str.index(new SeqString(new char[]{'x', 'y', 'z'}), 0));
//        System.out.println("在字符串后拼接hijkl串：");
//        CustString s = str.concat(str, new SeqString(new char[]{'h', 'i', 'j', 'k', 'l'}));
//        s.printStr();
        System.out.println("将字符串ab替换成opq：");
        str.replace(new SeqString(new char[]{'a', 'b'}), new SeqString(new char[]{'o', 'p', 'q'}));
        str.printStr();
        System.out.println("串长度：" + str.strLength());
        System.out.println("字符串反转：");
        str.strReverse();
        str.printStr();
    }

    public static void nextTest() {
        int[] next = str.getNext();
        for (int i = 0; i < next.length; i++) {
            System.out.print(next[i] + " ");
        }
        System.out.println();
    }

    public static void kmpTest() {
        System.out.print("匹配串cea：");
        CustString str1 = new SeqString(new char[]{'c', 'e', 'a'});
        System.out.println(str.kmp(1, str1));
    }
}
